package pers.gxm.facade;

import java.io.IOException;
import java.io.Writer;

public class HtmlWriter {
    private Writer writer;
    public HtmlWriter(Writer writer){
        this.writer = writer;
    }

    public void title(String title) throws IOException {
//        <html><head></head><body><h1></h1>
        writer.write("<html>\n");
        writer.write("<head><meta charset=\"utf-8\"><title>" + title + "</title></head>\n");
        writer.write("<body>\n<h1>" + title + "</h1>\n");
    }

    public void paragraph(String msg) throws IOException {
        writer.write("<p>" + msg + "</p>\n");
    }

    public void link(String href,String caption) throws IOException {
        paragraph("<a href=\"" + href + "\">" + caption + "</a>" );
    }

    public void mailto(String mailaddr,String username) throws IOException {
        link("mailto:" + mailaddr,username);
    }

    public void close() throws IOException {
        writer.write("</body>\n");
        writer.write("</html>\n");
        writer.close();
    }
}
